<template>
	<view class="body">
		<view class="search-box">
			<input type="text" placeholder="请输入或扫描产品条码" class="search-input" v-model="code" @confirm="doByInput" confirm-type="search"/>
			<view class="search-btn" @tap="doByInput">
				<image src="../../static/icons/icon_search2.png" class="btn-icon"></image>
			</view>
			<!-- /btn-group -->
		</view>
		<view class="divider">
			
		</view>	
		<!-- <view class="menu-wrapper">
			<input type="text" placeholder="请输入或扫描产品条码" class="input" :value="code" @confirm="doByInput" confirm-type="search"/>			
		</view>
		<view class="divider">
		</view> -->
		<view class="menu-wrapper">
			产品条码 : {{part_code}}
		</view>
		<view class="menu-wrapper">
			产品名称 : {{part_name}}
		</view>
		<view class="menu-wrapper">
			产品型号 : {{part_specs}}
		</view>
		<view class="menu-wrapper">
			货位编码 : {{inventlocdef_code}}
		</view>
		<view class="menu-wrapper">
			MPS : {{plnmpsb_id}}
		</view>
		<view class="menu-wrapper">
			订单编号 : {{saleord_ord}}
		</view>
		<view class="menu-wrapper">
			出/入库 : {{part_code_ck_status}}/{{part_code_rk_status}}
		</view>
		<view class="menu-wrapper">
			备注 : {{part_comment}}
		</view>
		<view class="menu-wrapper">
			修改人 : {{modify_who}}
		</view>
		<view class="menu-wrapper">
			修改日期 : {{modify_date}}
		</view>
	</view>
</template>

<script>
	import SCan from 'common/scan.js'
	
	export default {
		data() {
			return {
				code:"",
				part_code:"",
				inventlocdef_code:"",
				plnmpsb_id:"",
				part_code_amnt:"",
				part_code_rk_status:"",
				part_code_ck_status:"",
				modify_who:"",
				modify_date:"",
				part_name:"",
				part_id:"",
				part_specs:"",
				saleord_ord:"",
				part_comment:""
			}
		}, 
		onShow: function(){  
		    SCan.initScan(this.queryAndScan)  
		    SCan.startScan();  
		},  
		onHide:function(){  
		    SCan.stopScan();  
		},  
		onUnload:function(){
		    SCan.stopScan();
		}, 
		methods: {
			doByInput(e){
				var _this=this;
				_this.queryAndScan(_this.code);//e.detail.value
			},
			queryAndScan(code){
				var _this=this;
				_this.code=code;
				if(_this.code!=""){	
					//记录扫描记录
					var date=new Date();
					this.$config.SysConfig.TODAY_SCAN.push({
						page:'产品',
						code:code,
						date:date.getHours()+':'+date.getMinutes()+":" +date.getSeconds()
					})
					
					if(_this.$config.SysConfig.APP_ISONLINE){		
						//在线
						this.$common.isWifiExec(()=>{
							var param={
								barcode:_this.code.replace(/[\r\n]/g,""),
								type:"product"
							}
							_this.$http.scan(param).then(res=>{
								// console.log(res)
								if(res.code=='1'){
									_this.part_code=res.data.part_code
									_this.inventlocdef_code=res.data.inventlocdef_code
									_this.plnmpsb_id=res.data.plnmpsb_id
									_this.part_code_amnt=res.data.part_code_amnt
									_this.part_code_rk_status=res.data.part_code_rk_status
									_this.part_code_ck_status=res.data.part_code_ck_status
									_this.modify_who=res.data.modify_who
									_this.modify_date=res.data.modify_date
									_this.part_name=res.data.part_name
									_this.part_specs=res.data.part_specs
									_this.part_comment=res.data.part_comment
									_this.saleord_ord=res.data.saleord_ord	
								}
								else{
									_this.$common.playErrBeep(1)
									uni.showToast({
										icon:'none',
										title:res.msg,
										duration:1500
									})
									_this.part_code=""
									_this.inventlocdef_code=""
									_this.plnmpsb_id=""
									_this.part_code_amnt=""
									_this.part_code_rk_status=""
									_this.part_code_ck_status=""
									_this.modify_who=""
									_this.modify_date=""
									_this.part_name=""
									_this.part_specs=""
									_this.part_comment=""
									_this.saleord_ord=""
								}
								// console.log(res)
							})
						},()=>{
							uni.showToast({
								title:this.$config.msgs.needwifi,
								icon:'none',
								duration:1500
							})
							// uni.showToast(this.$config.msgs.needwifi)
							// _this.$common.playErrBeep(1)
						})
					}
					else
					{ //离线 无法查询
						uni.showToast({
							title:this.$config.msgs.needonline,
							icon:'none',
							duration:1500
						})
						// uni.showToast(this.$config.msgs.needonline)
						// _this.$common.playErrBeep(1)
					}
					
				}
				else {
					console.log('err')
					// _this.$common.playErrBeep(1)
				}
			}
		}
	}
</script>

<style>
.body{
	border-top: solid 1px #DBDBDA;
	padding: 0upx;
}
.input{
	width: 100%;
	height: 85upx;
	padding-right: 80upx;
	background: url('../../static/icons/qrcode.png') no-repeat scroll right center transparent;
}
.menu-wrapper{
	flex-direction: row;
	display: flex;
	margin-top: 25upx;
	padding: 5upx 35upx;
}
.menu-wrapper button{
	width: 160upx;
/* 	height: 85upx; */
	/* border-radius: 0; */
}

.search-box {
    display: flex;
	flex-direction: row;
	padding: 0upx 15upx;
}
.search-input {
   flex-grow: 11;
   height: 75upx;
   line-height: 80upx;
}
.search-btn {
    flex: 1;
	border: none;	
	padding: 10upx 10upx 5upx 10upx;
}
.btn-icon{
	width: 60upx;
	height: 60upx;
	line-height: 80upx;
}
.divider{
	border-top: solid 4upx #ADADAD;
	height: 1upx;
}
</style>
